package com.example.mybatisplus.web.controller;

import com.example.mybatisplus.model.domain.VisitInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.WorkService;
import com.example.mybatisplus.model.domain.Work;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2023-10-16
 * @version v1.0
 */
@Controller
@RequestMapping("/api/work")
public class WorkController {

    private final Logger logger = LoggerFactory.getLogger( WorkController.class );

    @Autowired
    private WorkService workService;

    /**
    * 描述：根据Id 查询
    *
    */
    @RequestMapping(value = "/getAllByWorkNum/{workNum}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse getAllByWorkNum(@PathVariable("workNum") Long workNum)throws Exception {
        Work  work =  workService.getAllByWorkNum(workNum);
        return JsonResponse.success(work);
    }
    //查询全部值班信息
    /*全部查询*/
    @RequestMapping("getTotal")
    @ResponseBody
    public JsonResponse getTotal(@RequestBody Work workInfo){
        List<Work> workInfos=workService.getTotal(workInfo);
        return JsonResponse.success(workInfos);
    }
    /*一次查出相应页数的数据并且可以模糊查询*/
    @RequestMapping(value="/getAll/{page}/{limit}")
    @ResponseBody
    public JsonResponse getAll(@PathVariable("page") Long page,@PathVariable("limit") Long limit,@RequestBody Work workInfo){
        List<Work> workInfos=workService.getAll(page,limit,workInfo);
        return JsonResponse.success(workInfos);
    }
    /*根据值班序号进行假删除多个删除*/
    @RequestMapping(value="/deleteByWorkNums")
    @ResponseBody
    public JsonResponse deleteByWorkNums(@RequestBody List<Long> workNums) {
        workService.deleteByWorkNums(workNums);
        return JsonResponse.success(null);
    }
    //增加一个值班表数据
    @RequestMapping(value="/addWork")
    @ResponseBody
    public JsonResponse addWork(@RequestBody Work workInfo){
        workService.addWork(workInfo);
        return JsonResponse.success(null);
    }
    //修改值班状态
    @RequestMapping(value="/workStatus/{workNum}/{isFree}")
    @ResponseBody
    public JsonResponse modifyStatus(@PathVariable("workNum") Long workNum, @PathVariable("isFree")Long isFree){
        workService.modifyStatus(workNum,isFree);
        return JsonResponse.success(null);
    }
    //修改值班的预约人数
    @RequestMapping(value="/modifyWorkNum/{workNum}/{num}")
    @ResponseBody
    public JsonResponse modifyWorkNum(@PathVariable("workNum") Long workNum,@PathVariable("num") Long num){
        workService.modifyWorkNum(workNum,num);
        return JsonResponse.success(null);
    }


    //修改值班信息
    @RequestMapping(value="/modifyWork")
    @ResponseBody
    public JsonResponse modifyWork(@RequestBody Work workInfo){
        workService.modifyWork(workInfo);
        return JsonResponse.success(null);
    }
}

